$().ready(function() {
	
	//dataTable('${oLanguage}','${pageContext.request.contextPath}');
});


jQuery.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
{
	return {
		"iStart":         oSettings._iDisplayStart,
		"iEnd":           oSettings.fnDisplayEnd(),
		"iLength":        oSettings._iDisplayLength,
		"iTotal":         oSettings.fnRecordsTotal(),
		"iFilteredTotal": oSettings.fnRecordsDisplay(),
		"iPage":          oSettings._iDisplayLength === -1 ?
			0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
		"iTotalPages":    oSettings._iDisplayLength === -1 ?
			0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
	};
};

function dataTable(data,path) {
var oLanguage = data.split(",");
$('#searchData').dataTable( {
	"bJQueryUI": true,
	"sPaginationType": "full_numbers",
	"oLanguage": {
        "oPaginate": {
                      "sFirst": oLanguage[0],// ปุ่มกลับมาหน้าแรก
                      "sLast": oLanguage[1],//ปุ่มไปหน้าสุดท้าย
                      "sNext": oLanguage[2], //ปุ่มหน้าถัดไป
                      "sPrevious": oLanguage[3] // ปุ่ม กลับ
                    	  },
         "sLengthMenu": oLanguage[4],  
         "sZeroRecords": oLanguage[5], 
         "sInfo": oLanguage[6],
         "sEmptyTable": oLanguage[7],
         "sLoadingRecords": oLanguage[8],
         "sProcessing": oLanguage[9],
         "sInfoEmpty": oLanguage[10],
         "sInfoFiltered": oLanguage[11],  
         "sSearch": oLanguage[12]
    },
	"fnRowCallback" : function(nRow, aData, iDisplayIndex){
        $("td:first", nRow).html(iDisplayIndex +1);
       return nRow;
    },
    "bProcessing": true,
//    "bServerSide": true,
//    "sort": "position",
    "bStateSave": false,
    "iDisplayLength": 10,
    "iDisplayStart": 0,
    "fnDrawCallback": function () {   
    },         
    "sAjaxSource": "account/accountDataTable",
    "aoColumns": [
		{ "mData": null,sClass: "center", sWidth: '5%'},
		{ "mData": "vaCodeId",sClass: "left", sWidth: '5%' },
		{ "mData": "vaDescription",sClass: "left", sWidth: '20%'  },
		{ "mData": null,"mRender": function ( data, type, full ) {
			var poObject = [full.vaApplicationId,full.vaApplicationName,full.vaImageUrl,full.vaLink];
			
		    return "<button onclick=\"manageData()\" class='btn btn-default btn-sm'><i class='fa fa-file-text-o'></i></button><button onclick=\"editData('"+poObject+"')\" class='btn btn-info btn-sm'><i class='fa fa-edit'></i></button>"+
    		"<button onclick=\"deleteData('"+full.vaApplicationId+"')\" class='btn btn-warning btn-sm'><i class='fa fa-trash-o'></i></button>";
		    }
		, sWidth: '10%',sClass: "center"},
    ]} 
);

$('#chk-all').click(function()	{
	if($(this).is(':checked'))	{
		$('#responsiveTable').find('.chk-row').each(function()	{
			$(this).prop('checked', true);
			$(this).parent().parent().parent().addClass('selected');
		});
	}
	else	{
		$('#responsiveTable').find('.chk-row').each(function()	{
			$(this).prop('checked' , false);
			$(this).parent().parent().parent().removeClass('selected');
		});
	}
});
}





